package com.zsxb.crm.controller;

import com.zsxb.crm.annotation.Log;
import com.zsxb.crm.constant.ClueStatusConstant;
import com.zsxb.crm.dto.*;
import com.zsxb.crm.pojo.Clue;
import com.zsxb.crm.result.PageResult;
import com.zsxb.crm.result.Result;

import com.zsxb.crm.service.ClueService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/clues")
@Slf4j
@RequiredArgsConstructor
public class ClueController {
    private final ClueService clueService;

    /**
     * 线索分页查询
     * @param clueSearchDto
     * @return
     */
    @GetMapping("/clue/list")
    public PageResult pageQuery(ClueSearchDto clueSearchDto){
        log.info("clue接收参数:{}",clueSearchDto);
        PageResult pageResult = clueService.pageQuery(clueSearchDto);
        return PageResult.success(pageResult);
    }

    /**
     * 新增线索
     * @param dto
     * @return
     */
    @PostMapping("/clue")
    @Log
    public Result addClue(@RequestBody AddClueDTO dto){
        log.info("新增线索参数:{}",dto);
        clueService.add(dto);
        return Result.success();
    }

    /**
     * 根据线索id查询线索和线索池
     * @param clueId
     * @return
     */
    @GetMapping("/clue/{clueId}")
    public Result getById(@PathVariable("clueId") Long clueId){
        log.info("查询线索池参数:{}",clueId);
        Clue clue = clueService.getByClueId(clueId);
        return Result.success(clue);
    }

    /**
     * 捞取线索
     * @param
     * @return
     */
    @PutMapping("/clue/gain")
    @Log
    public Result gain(@RequestBody ClueGainDTO clueGainDTO){
        log.info("捞取线索参数:{}",clueGainDTO);
        clueService.gain(clueGainDTO);
        return Result.success("全部捞取成功");
    }


    /**
     * 线索池分页查询
     * @param clueSearchDto
     * @return
     */
    @GetMapping("/clue/pool")
    public PageResult pageQueryPool(ClueSearchDto clueSearchDto){
        log.info("查询线索池参数:{}",clueSearchDto);
        PageResult pageResult = clueService.poolPageQuery(clueSearchDto);
        return PageResult.success(pageResult);
    }

    @GetMapping("/record/list")
    public PageResult findRecordByClueId(Long clueId){
        PageResult pageResult = clueService.findRecordByClueId(clueId);
        return PageResult.success(pageResult);
    }

    @PutMapping("/clue/false/{clueId}")
    @Log
    public Result backCluePool(@PathVariable Long clueId,@RequestBody ClueRecrodDTO clueRecrodDTO){
        clueService.backCluePool(clueId,clueRecrodDTO);
        return Result.success();
    }

    @PutMapping("/clue/assignment")
    @Log
    public Result assign(@RequestBody ClueGainDTO clueGainDTO){
        clueService.assign(clueGainDTO);
        return Result.success();
    }

    @PostMapping("record")
    @Log
    public Result<String> addClueDetail(@RequestBody ClueDTO clueDTO){
        clueService.addClueDetail(clueDTO);
        return Result.success();
    }
}
